<?php
class Test extends IController
{
    public function index(){
        $this->redirect("login_di");
    }
    public function add_do(){
        $uname=IReq::get("uname");
        $dizi=IReq::get("dizi");
        $pass = IFilter::act(IReq::get("pass"),'int');
        $model = new IModel("testuser");
        // print_r($pass);
        $arr = array('uname'=>$uname,'pass'=>$pass,'dizi'=>$dizi);

        $model->setData($arr);
        $res = $model->add();
        // $res = $model->add();
        // $result = $model->add();
        if ($res) {
            $this->redirect("show");
        } else {
            $this->redirect("adds.html");
        }
        
    }
    public function show(){
        $model = new IModel("testuser");
        $res = $model->query();
        // echo $res;
        // var_dump($res);
        $this->setRenderData(['res'=>$res]);
        $this->redirect("show");
    }
    public function iptest(){
        // echo "<pre>";
        // print_r($_SERVER);
    }
    public function ajax(){
        echo "string";
        $address=$_POST['adds'];
        $ak="jBhtftnoivHwS5EypucQkZWaomEIuQcN";
        $url="http://api.map.baidu.com/geocoder/v2/?address=$address&output=json&ak=$ak";
        $data=file_get_contents($url);
        $data=json_decode($data,ture);
        $arr['lat']=$data['result']['location']['lat'];
        $arr['lng']=$data['result']['location']['lng'];
        // echo "<pre>";
        // print_r($data);
        echo json_decode($arr);
    }
    public function login(){
        $this->redirect("login");
    }




    public function login_do(){
                $uname=IReq::get('uname');
                $pass=IReq::get('pass');
                $model=new IModel("testuser");
                $data=$model->query("uname='$uname' and pass = '$pass'");
                // print_r($data);die;
                if($data){
                    echo "登陆成功";
                    $_SESSION['uid']=$data[0]['id'];
                    // echo $_SESSION['uid'];die;
                    $this->redirect("show");
                }else{
                    echo "账户或密码有误";
                }
    }
    public function do_ss(){
        $this->redirect("qqlogin");
    }
    public function ditu_name(){
    	$this->redirect("login_id");
    }
    public function qq_login(){
        $appid='101353491';         // APPID
        //$appkey='df4e46ba7da52f787c6e3336d30526e4';         // APPKEY
        $redirect_uri='http://www.iwebshop.com/index.php';      // 回调地址
        $state=rand(1000,9000);
        $url="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&state=$state";
        // echo $url;
        // print_r($url);
       //     http://graph.qq.com/demo/index.jsp?code=9A5F************************06AF&state=test
        header("Location:$url");
    }
    public function zhuan(){
        $this->redirect("api_adds");
    }
    public function api_add()
    {
        $url = 'http://api.k780.com:88/?app=weather.future&weaid=$name&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json';
        $content = file_get_contents($url);
        $result=json_decode($content,true);
        print_r($result);exit;
        //城市
        // $this->assign('currentCity',$result['results'][0]['currentCity']);
        // //气温
        // $this->assign('temperature',$result['results'][0]['weather_data'][0]['temperature']);
        // //天气状况
        // $this->assign('weather',$result['results'][0]['weather_data'][0]['weather']);
        // //天气图片dayPictureUrl
        // $this->assign('dayPictureUrl',$result['results'][0]['weather_data'][0]['dayPictureUrl']);
        // return $this->fetch();
    }
    public function file_big(){
        $this->redirect("bigfile");
    }
    public function bigFileUplaod(){
        // echo "11111";
        $sliceNo=$_POST['sliceNo'];
        // echo $sliceNo;die;
        $filename=$_POST['filename'];
        // print_r($filename);die;
        $blod_count=$_POST['blod_count'];
        $sliceFile=$_FILES['sliceFile'];
        // print_r($sliceFile);
        // var_dump($sliceFile);
        $tmp_name=$sliceFile['tmp_name'];
        $this->moveSliceFile($tmp_name,$filename,$sliceNo);
        if ($sliceNo==$blod_count) {
            $this->mergeSliceFile($sliceNo,$filename);
            $this->deleteSliceFile($sliceNo,$filename);
        }
        // print_r($sliceNo);
    }
    public function moveSliceFile($tmp_name,$filename,$sliceNo)
    {
        $destination = "upload/video/".$filename.'_'.$sliceNo;
        print_r($tmp_name);die;
        move_uploaded_file($tmp_name,$destination);
    }
    public function mergeSliceFile($sliceNo,$filename){
        // print_r('11111');die;
        // $data="";
        // for ($i=1; $i <= $sliceNo; $i++) { 
        //     $new_name = "upload/video/".$filename.'_'.$i;
        //     // print_r($new_name);die;
        //     $data.=file_get_contents($new_name);
        // }
        // $new_name="upload/video/".$filename;
        // file_put_contents($new_name,$data);
    }
}

?>